package com.xxxx.matchTest

/**
 * @program: day0303
 * @description: 尽信书，则不如无书
 * @author: CoreDao
 * @create: 2021-03-03 16:46
 * */

object MatchTest {
  def main(args: Array[String]): Unit = {

    val tuple = (1, "2", 6.0f, 'c')
    val iterator = tuple.productIterator
    while (iterator.hasNext) {
      //在这里面对遍历出来的内容进行模式匹配
      test_match(iterator.next())

    }

    /**
     * 可以进行值、类型等匹配，功能强大
     * 不需要break，没有default
     * 匹配有先后顺序，先匹配先截取，如下面的"2"
     * @param x
     */

    def test_match(x:Any)={
      x match {
        case _:String => println("match is string")
        case 1 => println("match is 1")
        case "2" => println("match String 2")
        case 6.0f => println("match float 6.0")
        case 'c' => println("match char c")
        case _ => println("no")
      }
    }
  }

}
